home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performOffsetCos.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.2 KB  |  574 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  29 April 1997
  22. //  Author:         mpw
  23. //
  24. //  Description:
  25. //        Initialize the option values for offset curve on surface menu item.
  26. //
  27. //  Input Arguments:
  28. //      int action
  29. //          0 - just execute the offset curve operation
  30. //        1 - show the option box dialog
  31. //          2 - drag to shelf
  32. //
  33. //  Return Value:
  34. //      None.
  35. //
  36.  
  37. proc setOptionVars(int $forceFactorySettings)
  38. {
  39.     // Global or local tolerance:
  40.     if( $forceFactorySettings || !`optionVar -exists offsetCosUseGlobalTol` ){
  41.         optionVar -intValue offsetCosUseGlobalTol false;
  42.     }
  43.  
  44.     //    Connect breaks (0=off 1=circular 2=linear).
  45.     //
  46.     if ($forceFactorySettings || !`optionVar -exists offsetCosConnectBreaks`) {
  47.         optionVar -intValue offsetCosConnectBreaks 2;
  48.     }
  49.  
  50.     //    Stitch (on-1 or off-0).
  51.     //
  52.     if ($forceFactorySettings || !`optionVar -exists offsetCosStitch`) {
  53.         optionVar -intValue offsetCosStitch 1;
  54.     }
  55.  
  56.     //    Cut loops (on-1 or off-0).
  57.     //
  58.     if ($forceFactorySettings || !`optionVar -exists offsetCosCutLoop`) {
  59.         optionVar -intValue offsetCosCutLoop 0;
  60.     }
  61.  
  62.     //    Offset distance.
  63.     //
  64.     if ($forceFactorySettings || !`optionVar -exists offsetCosDistance`) {
  65.         optionVar -floatValue offsetCosDistance 1.0;
  66.     }
  67.  
  68.     //    Tolerance control (on-1 or off-0 used for depth and bias).
  69.     //
  70.     if ($forceFactorySettings || !`optionVar -exists offsetCosTolerance`) {
  71.         optionVar -floatValue offsetCosTolerance 0.01;
  72.     }
  73.  
  74.     //    Subdivision density
  75.     //
  76.     if ($forceFactorySettings || !`optionVar -exists offsetCosSubdivDensity`) {
  77.         optionVar -intValue offsetCosSubdivDensity 5;
  78.     }
  79.  
  80.     // curve range
  81.     if ($forceFactorySettings ||
  82.         !`optionVar -exists offsetCosRangePartial`){
  83.         optionVar -intValue offsetCosRangePartial 0;
  84.     }
  85.  
  86. }
  87.  
  88. //
  89. //  Procedure Name:
  90. //      offsetCosSetup
  91. //
  92. //  Description:
  93. //        Update the state of the option box UI to reflect the offsetCos
  94. //        option values.
  95. //
  96. //  Input Arguments:
  97. //      parent               - Top level parent layout of the option box UI.
  98. //                             Required so that UI object names can be 
  99. //                             successfully resolved.
  100. //
  101. //        forceFactorySettings - Whether the option values should be set to
  102. //                             default values.
  103. //
  104. //  Return Value:
  105. //      None.
  106. //
  107. global proc offsetCosSetup( string $parent,
  108.                             int $forceFactorySettings,
  109.                             string $goToTool )
  110. {
  111.     //    Retrieve the option settings
  112.     //
  113.     setOptionVars($forceFactorySettings);
  114.     offsetCosToolSetup( $forceFactorySettings, $goToTool );
  115.  
  116.     setParent $parent;
  117.  
  118.     //    Query the optionVar's and set the values into the controls.
  119.  
  120.     // Global vs. local tolerance
  121.     int $useGlobalTol = `optionVar -q offsetCosUseGlobalTol`;
  122.     radioButtonGrp -e -sl (2 - $useGlobalTol) useGlobalTol;
  123.  
  124.     //    Distance
  125.     //
  126.     floatSliderGrp -edit 
  127.         -value `optionVar -q offsetCosDistance`
  128.         offsetCosDistanceFloatSliderGrp;
  129.  
  130.     //    Connect breaks.
  131.     //
  132.     int $doConnectBreaks = `optionVar -q offsetCosConnectBreaks`;
  133.     if( 0 == $doConnectBreaks ) $doConnectBreaks = 3;
  134.     radioButtonGrp -edit 
  135.         -sl $doConnectBreaks
  136.         offsetCosConnectBreaksRadioButtonGrp;
  137.  
  138.     //    Loop cutting.
  139.     //
  140.     int $doCutLoop = `optionVar -q offsetCosCutLoop`;
  141.     radioButtonGrp -edit 
  142.         -sl (2 - $doCutLoop)
  143.         offsetCosCutLoopRadioButtonGrp;
  144.  
  145.     //    Subdivision density
  146.     //
  147.     intSliderGrp -edit 
  148.         -value `optionVar -q offsetCosSubdivDensity`
  149.         offsetCosSubdivDensityIntSliderGrp;
  150.  
  151.     //    Tolerance
  152.     //
  153.     floatSliderGrp -edit 
  154.         -v `optionVar -q offsetCosTolerance`
  155.         offsetCosTolerance;
  156.  
  157.     // curve range on inputs.
  158.     //
  159.     int $offsetCosRangePartial = `optionVar -q offsetCosRangePartial`+1 ;
  160.     radioButtonGrp -edit -sl $offsetCosRangePartial 
  161.         offsetCosRangeRadioButtonGrp ;        
  162.  
  163.     if( $useGlobalTol ) {
  164.         tabLayout -e -selectTab noSlider useGlobalTolTab;
  165.     }
  166.     else {
  167.         tabLayout -e -selectTab slider useGlobalTolTab;
  168.     }
  169.  
  170.     if( "" != $goToTool ) { 
  171.         checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool`
  172.           scriptToolExtraWidget;
  173.         checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool`
  174.           scriptToolExtraWidget;
  175.     }
  176. }
  177.  
  178. //
  179. //  Procedure Name:
  180. //      offsetCosCallback
  181. //
  182. //  Description:
  183. //        Update the option values with the current state of the option box UI.
  184. //
  185. //  Input Arguments:
  186. //      parent - Top level parent layout of the option box UI.  Required so
  187. //               that UI object names can be successfully resolved.
  188. //
  189. //        doIt   - Whether the command should execute.
  190. //
  191. //  Return Value:
  192. //      None.
  193. //
  194. global proc offsetCosCallback(string $parent, int $doIt, string $goToTool)
  195. {
  196.     if( "" != $goToTool ) {
  197.         optionVar -iv offsetCosEuc `scriptCtx -q -euc $goToTool`;
  198.         optionVar -iv offsetCosLac `scriptCtx -q -lac $goToTool`;
  199.     }
  200.     setParent $parent;
  201.  
  202.     //    Set the optionVar's from the control values, and then
  203.     //    perform the command.
  204.  
  205.     // get Values from controls.
  206.     int $offsetCosRangePartial = `radioButtonGrp -q -sl offsetCosRangeRadioButtonGrp` - 1 ;
  207.     optionVar -intValue offsetCosRangePartial $offsetCosRangePartial;
  208.  
  209.     // distance
  210.     optionVar -floatValue offsetCosDistance
  211.         `floatSliderGrp -q -value offsetCosDistanceFloatSliderGrp`;
  212.  
  213.     // connect breaks
  214.     int $breaks = `radioButtonGrp -q -sl offsetCosConnectBreaksRadioButtonGrp`;
  215.     if( 3 == $breaks ) $breaks = 0;
  216.     optionVar -intValue offsetCosConnectBreaks $breaks;
  217.  
  218.     // loop cutting
  219.     int $lc = 2 - `radioButtonGrp -q -sl offsetCosCutLoopRadioButtonGrp`;
  220.     optionVar -intValue offsetCosCutLoop $lc;
  221.  
  222.     // subdivision density
  223.     optionVar -intValue offsetCosSubdivDensity
  224.         `intSliderGrp -q -value offsetCosSubdivDensityIntSliderGrp`;
  225.  
  226.     // tolerance
  227.     optionVar -floatValue offsetCosTolerance
  228.         `floatSliderGrp -q -v offsetCosTolerance`;
  229.  
  230.     // global vs. local:
  231.     int $useGlobalTol = 2 - `radioButtonGrp -q -sl useGlobalTol`;
  232.     optionVar -intValue offsetCosUseGlobalTol $useGlobalTol;
  233.  
  234.     if (1 == $doIt) {
  235.         performOffsetCos( 0, $goToTool ); 
  236.         string $tmpCmd = "performOffsetCos( 0, \"" + $goToTool + "\")";
  237.         addToRecentCommandQueue $tmpCmd "Offset Curve On Surface";
  238.     }
  239.     else if( $doIt ) {
  240.         setToolTo $goToTool;
  241.     }
  242. }
  243.  
  244. //
  245. //  Procedure Name:
  246. //      createoffsetCosUI
  247. //
  248. //  Description:
  249. //        Fill the contents of the option box for offsetCos command.
  250. //
  251. //  Input Arguments:
  252. //      The name of the parent layout.
  253. //
  254. //  Return Value:
  255. //      None.
  256. //
  257. proc createOffsetCosUI(string $parent, int $inTheTool, string $goToTool)
  258. {
  259.    setParent $parent;
  260.  
  261.    floatSliderGrp -field on -fmn -1000. -fmx 1000. 
  262.        -min -10. -max 10. 
  263.        -l "Offset Distance"
  264.        offsetCosDistanceFloatSliderGrp;
  265.  
  266.    radioButtonGrp -nrb 3 -sl 1 
  267.        -l "Connect Breaks"
  268.        -l1 "Circular" -da1 1
  269.        -l2 "Linear" -da2 2
  270.        -l3 "Off" -da3 0
  271.        offsetCosConnectBreaksRadioButtonGrp;
  272.  
  273.    string $tabLayoutName = (`setParent -q` + "|offsetCosLoopCutOptions_Tabs");
  274.  
  275.    radioButtonGrp -nrb 2 -sl 1 
  276.        -l "Loop Cutting"
  277.        -l1 "On" -da1 1
  278.        -l2 "Off" -da2 0
  279.        offsetCosCutLoopRadioButtonGrp;
  280.    
  281.    intSliderGrp -field on -min 0 -max 10 
  282.        -fmn 0 -fmx 100 
  283.        -l "Max Subdivision Density"
  284.        offsetCosSubdivDensityIntSliderGrp;
  285.  
  286.    radioButtonGrp -nrb 2 -l "Use Tolerance"
  287.        -l1 "Global"
  288.        -l2 "Local"
  289.        -on1 "tabLayout -e -selectTab noSlider useGlobalTolTab"
  290.        -on2 "tabLayout -e -selectTab slider useGlobalTolTab"
  291.        useGlobalTol;
  292.  
  293.    tabLayout -tabsVisible false useGlobalTolTab;
  294.        columnLayout slider;
  295.            floatSliderGrp -l "Tolerance"
  296.                -min 0.001 -max 1.0 -fmn 0.00001 -fmx 10.0
  297.                offsetCosTolerance;
  298.        setParent ..;
  299.        columnLayout noSlider;
  300.        setParent ..;
  301.    setParent ..;
  302.  
  303.    separator;
  304.  
  305.     // layout for add curve range, create as polygons.
  306.     //
  307.    radioButtonGrp -nrb 2 -label "Curve Range" -label1 "Complete" -da1 0 -label2 "Partial" -da2 1 -sl 1 offsetCosRangeRadioButtonGrp;
  308.  
  309.     if( $inTheTool ) {
  310.         separator;
  311.         checkBoxGrp -ncb 2 -l "Tool Behavior"
  312.           -l1 "Exit on Completion"
  313.           -v1 off
  314.           -on1 ("scriptCtx -e -euc true " + $goToTool)
  315.           -of1 ("scriptCtx -e -euc false " + $goToTool)
  316.  
  317.           -l2 "Auto Completion"
  318.           -v2 on
  319.           -on2 ("scriptCtx -e -lac true " + $goToTool)
  320.           -of2 ("scriptCtx -e -lac false " + $goToTool)
  321.           scriptToolExtraWidget;
  322.     }
  323. }
  324.  
  325. //
  326. //  Procedure Name:
  327. //      offsetCosOptions
  328. //
  329. //  Description:
  330. //        Construct the option box UI.  Involves accessing the standard option
  331. //        box and customizing the UI accordingly.
  332. //
  333. //  Input Arguments:
  334. //      None.
  335. //
  336. //  Return Value:
  337. //      None.
  338. //
  339. proc offsetCosOptions( int $inTheTool, string $goToTool )
  340. {
  341.     //    Name of the command for this option box.
  342.     //
  343.     string $commandName = "offsetCos";
  344.     string $optionBoxTitle;
  345.     if( $inTheTool ) {
  346.         $optionBoxTitle = "Offset Curve On Surface Tool Options" ;
  347.     }
  348.     else {
  349.         $optionBoxTitle = "Offset Curve On Surface Options" ;
  350.     }
  351.  
  352.     //    Build the option box actions.
  353.     //
  354.     string $callback = ($commandName + "Callback");
  355.     string $setup = ($commandName + "Setup");
  356.  
  357.     global string $gOptionBoxActionToolItem;
  358.     $gOptionBoxActionToolItem = "modelWithToolOffsetCoS";
  359.     global string $gOptionBoxActionToolItemCB;
  360.     $gOptionBoxActionToolItemCB = "offsetCosToolScript 3";
  361.  
  362.     //  The value returned is the name of the layout to be used as
  363.     //    the parent for the option box UI.
  364.     //
  365.     string $layout = getOptionBox();
  366.     setParent $layout;
  367.     
  368.     //    Pass the command name to the option box.
  369.     //
  370.     //    Any default option box behavior based on the command name is set 
  371.     //    up with this call.
  372.     //
  373.     setOptionBoxCommandName("offsetCurveOnSurface");
  374.     
  375.     //    Activate the default UI template so that the layout of this 
  376.     //    option box is consistent with the layout of the rest of the 
  377.     //    application.
  378.     //
  379.     setUITemplate -pushTemplate DefaultTemplate;
  380.  
  381.     //    Turn on the wait cursor.
  382.     //
  383.     waitCursor -state 1;
  384.  
  385.     //    RECOMMENDATION:  Place the UI in a scroll layout.  If the 
  386.     //    option box window is ever resized such that it's entire 
  387.     //    contents is not visible then the scroll bars provided by the
  388.     //    scroll layout will allow the user to access the hidden UI.
  389.     //
  390.     tabLayout -scr true -tv false;
  391.     
  392.     string $parent = `columnLayout -adjustableColumn 1`;
  393.  
  394.     //    Create the UI for the tab that is initially visible.
  395.     //
  396.     createOffsetCosUI($parent, $inTheTool, $goToTool);
  397.  
  398.     //    Turn off the wait cursor.
  399.     //
  400.     waitCursor -state 0;
  401.  
  402.     //    Deactivate the default UI template.
  403.     //
  404.     setUITemplate -popTemplate;
  405.  
  406.     //    Attach actions to those buttons that are applicable to the option
  407.     //    box.  Note that the 'Close' button has a default action attached 
  408.     //    to it that will hide the window.  If a a custom action is
  409.     //    attached to the 'Close' button then be sure to call the 'hide the
  410.     //    option box' procedure within the custom action so that the option
  411.     //    box is hidden properly.
  412.  
  413.     //    'offsetCos' button.
  414.     //
  415.     string $applyBtn = getOptionBoxApplyBtn();
  416.     if( $inTheTool ) {
  417.         button -edit
  418.             -label "Offset Tool"
  419.             -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"")
  420.             $applyBtn;
  421.     }
  422.     else {
  423.         button -edit
  424.             -label "Offset"
  425.             -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"")
  426.             $applyBtn;
  427.     }
  428.  
  429.     //    'Save' button.
  430.     //
  431.     string $saveBtn = getOptionBoxSaveBtn();
  432.     button -edit 
  433.         -command ($callback + " " + $parent + " 0 \"" +
  434.                   $goToTool + "\"; hideOptionBox")
  435.         $saveBtn;
  436.  
  437.     //    'Reset' button.
  438.     //
  439.     string $resetBtn = getOptionBoxResetBtn();
  440.     button -edit 
  441.         -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"")
  442.         $resetBtn;
  443.  
  444.     //    Set the option box title.
  445.     //
  446.     setOptionBoxTitle($optionBoxTitle);
  447.  
  448.     //    Customize the 'Help' menu item text.
  449.     //
  450.     setOptionBoxHelpTag( "OffsetCurveOnSurface" );
  451.  
  452.     //    Set the current values of the option box.
  453.     //
  454.     eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\"");    
  455.     
  456.     //    Show the option box.
  457.     //
  458.     showOptionBox();
  459. }
  460.  
  461. //
  462. //  Procedure Name:
  463. //      offsetCosHelp
  464. //
  465. //  Description:
  466. //        Returns a short description about the offsetCos command.
  467. //
  468. //  Input Arguments:
  469. //      None.
  470. //
  471. //  Return Value:
  472. //      string.
  473. //
  474. proc string offsetCosHelp()
  475. {
  476.     return 
  477.     "  Command: offsetCos - create a offset 2d curve from a 2d curve.\n" +
  478.     "Select at least one curve on surface to offset.";    
  479. }
  480.  
  481. //
  482. //  Procedure Name:
  483. //      assembleCmd
  484. //
  485. //  Description:
  486. //        Construct the offsetCos command that will apply the option box 
  487. //        values.
  488. //
  489. //  Input Arguments:
  490. //      None.
  491. //
  492. //  Return Value:
  493. //      The offsetCos command string.
  494. //
  495. proc string assembleCmd()
  496. {
  497.     setOptionVars(false);
  498.  
  499.     string $cmd = "offsetCosPreset";
  500.     $cmd = $cmd + "(" ;
  501.  
  502.     // get the global history flag value
  503.     int $doHistory = `constructionHistory -q -tgl`;
  504.     $cmd = $cmd + $doHistory + ",";
  505.     int $curveRangePartial = `optionVar -q offsetCosRangePartial`;
  506.     $cmd = $cmd + $curveRangePartial + "," ;  
  507.     int $connectBreaks = `optionVar -q offsetCosConnectBreaks`;
  508.     $cmd = $cmd + $connectBreaks + ",";
  509.     int $stitch = `optionVar -q offsetCosStitch`;
  510.     $cmd = $cmd + $stitch + ",";
  511.     int $cutLoop = `optionVar -q offsetCosCutLoop`;
  512.     $cmd = $cmd + $cutLoop + ",";
  513.     float $distance = `optionVar -q offsetCosDistance`;
  514.     $cmd = $cmd + $distance + ",";
  515.     float $tolerance = `optionVar -q offsetCosTolerance`;
  516.     if( `optionVar -q offsetCosUseGlobalTol` ) {
  517.         $tolerance = `optionVar -q positionalTolerance`;
  518.     }
  519.  
  520.     $cmd = $cmd + $tolerance + ",";
  521.     int $subdivDensity = `optionVar -q offsetCosSubdivDensity`;
  522.     $cmd = $cmd + $subdivDensity;
  523.     $cmd = $cmd + ")";
  524.  
  525.     return $cmd;
  526. }
  527.  
  528. //
  529. //  Procedure Name:
  530. //      performoffsetCos
  531. //
  532. //  Description:
  533. //        Perform the offsetCos command using the corresponding 
  534. //        option values.  This procedure will also show the option box
  535. //        window if necessary as well as construct the command string
  536. //        that will invoke the offsetCos command with the current
  537. //        option box values.
  538. //
  539. //  Input Arguments:
  540. //      0 - Execute the command.
  541. //      1 - Show the option box dialog.
  542. //      2 - Return the command to drag to shelf.
  543. //
  544. //  Return Value:
  545. //      The offsetCos command string.
  546. //
  547. global proc string performOffsetCos( int $action, string $goToTool )
  548. {
  549.     int $inTheTool = false;
  550.     if( 3 == $action ) {
  551.         $action = 1;
  552.         $inTheTool = true;
  553.     }
  554.  
  555.     string $cmd = "";
  556.     switch ($action) {
  557.       case 0:
  558.         setOptionVars(false);
  559.         $cmd = `assembleCmd`;
  560.         eval($cmd);
  561.         break;
  562.  
  563.       case 1:
  564.         offsetCosOptions( $inTheTool, $goToTool );
  565.         break;
  566.  
  567.       case 2:
  568.         setOptionVars(false);
  569.         $cmd = `assembleCmd`;
  570.         break;
  571.     }
  572.     return $cmd;
  573. }
  574.